package com.xxx.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/26  10:05
 * @Copyright
 */
public class RefDome02 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> aClass = Class.forName("com.xxx.reflect.Student");
        Field[] fields = aClass.getFields();
        // Field declaredField = aClass.getDeclaredField();
        for (Field field : fields) {
            System.out.println("field = " + field);
        }

        Field name = aClass.getDeclaredField("name");
        Constructor<?> constructor = aClass.getConstructor(String.class);
        constructor.setAccessible(true);
        Student instance = (Student) constructor.newInstance("张三");

    }
}
